//
//  CensusTableViewCell.m
//  魔兽大数据
//
//  Created by 王右 on 2017/11/14.
//  Copyright © 2017年 王右. All rights reserved.
//

#import "CensusTableViewCell.h"
#import "BigDataProportionView.h"
#import "ServerPlayerListModel.h"
#import "BigDataHeader.h"

@interface CensusTableViewCell()

//比例展示
@property (strong, nonatomic) IBOutlet UIView *compareDataView;
//服务器名称
@property (weak, nonatomic) IBOutlet UILabel *serverNameLabel;
//服务器类型
@property (weak, nonatomic) IBOutlet UILabel *serverTypeLabel;
//总人口
@property (weak, nonatomic) IBOutlet UILabel *totalCountLabel;
//阵营优势比较
@property (weak, nonatomic) IBOutlet UILabel *ascendancyLabel;
//更新时间
@property (weak, nonatomic) IBOutlet UILabel *updateTimeLabel;

@property (nonatomic, strong) BigDataProportionView *compareView;

@end


@implementation CensusTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _compareView = [[[NSBundle mainBundle] loadNibNamed:@"BigDataProportionView" owner:nil options:nil] firstObject];
    _compareView.frame = CGRectMake(0, 0, _compareView.bounds.size.width, _compareDataView.bounds.size.height);
    [_compareDataView addSubview:_compareView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setModel:(ServerPlayerListModel *)model{
    if (model) {
        _model = model;
        
        _serverNameLabel.text = model.realmName;
        
        _serverTypeLabel.text = model.type.length ? model.type: @"PVE";
        
        _totalCountLabel.text = [NSString stringWithFormat:@"总人口:%@",model.sum];
        
        _ascendancyLabel.text = [self returnAscendancyLabelTextWithHordeNumber:model.horde alliance:model.alliance label:_ascendancyLabel];
        _updateTimeLabel.text = [model.updateTime retureTimeStringWithFormate:@"yyyy-MM-dd hh:mm" multiple:1000];
        
        [_compareView setDataWithAllianceNumbers:model.alliance.floatValue horderNumbers:model.horde.floatValue];

    }
}

- (NSString *)returnAscendancyLabelTextWithHordeNumber:(NSString *)horde alliance:(NSString *)alliance label:(UILabel *)label{
    float hordeNumber = horde.floatValue;
    float allianceNumber = alliance.floatValue;
    
    float radio = hordeNumber / allianceNumber;
    
    if (radio > 1.2) {
        label.textColor = [UIColor colorWithHexString:@"#a00a0f"];
        return @"部落优势";
    }else if (radio < 0.8){
        label.textColor = [UIColor colorWithHexString:@"#3c96ee"];
        return @"联盟优势";
    }else{
        label.textColor = [UIColor colorWithHexString:@"#5c5c57"];
        return @"阵营均势";
    }
}









@end
